from pydantic import BaseModel, Field


class InterfaceInfoSchema(BaseModel):
    interface_name: str = Field(..., description="接口名称")
    import_package_path: str = Field(None, description="接口导包路径")
    interface_define_content: str = Field(None, description="接口定义内容")
    interface_implement_example: str = Field(None, description="接口实现示例")


# 定义mcp工具函数
def interface_tool(
        interface_name_list: list[str] = Field(..., description="接口名称列表")
) -> list[InterfaceInfoSchema]:
    items = []
    for interface_name in interface_name_list:
        item = fetch_interface_info(interface_name)
        items.append(item)
    return items


def fetch_interface_info(interface_name: str) -> InterfaceInfoSchema:
    resp = InterfaceInfoSchema(interface_name=interface_name)
    if interface_name == 'ConfigType':
        resp.interface_define_content, resp.interface_implement_example, resp.import_package_path = ConfigTypeInterface()
    else:
        raise Exception('接口名称不存在')
    return resp


def ConfigTypeInterface() -> (str, str, str):
    content = """// ConfigType 模板配置 interface
type ConfigType interface {
	ToJson() (string, error)                  // 转json
	ToEntity(data string) (ConfigType, error) // 转实体
}
"""
    implement_example = """import (
	"tongquetai_server/activity_sd/domain/activity_manage"
	"tongquetai_server/share/infrastructure/utils"
	"tongquetai_server/share/infrastructure/utils/json"
)

type TqtConfig struct{}

func (t *TqtConfig) ToJson() (string, error) {
	return json.JsonMarshalString(t)
}

func (t *TqtConfig) ToEntity(data string) (activity_manage.ConfigType, error) {
	tqtConfig := &TqtConfig{}
	err := utils.JsonUnmarshal(data, tqtConfig)
	if err != nil {
		return nil, err
	}
	return tqtConfig, nil
}
    """
    import_package_path = "tongquetai_server/activity_sd/domain/activity_manage"
    return content, implement_example, import_package_path
